unit GMedPlotis;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, GForm, cxGraphics, cxPropertiesStore, dxBarExtItems, dxBar,
  cxClasses, ActnList, dxStatusBar, cxControls, cxPC, cxStyles, cxCustomData,
  cxFilter, cxData, cxDataStorage, cxEdit, DB, cxDBData, cxGridLevel,
  cxGridCustomTableView, cxGridTableView, cxGridDBTableView, cxGridCustomView,
  cxGrid, cxNavigator, cxDBNavigator, cxContainer, cxGroupBox, cxCalc, impexp,
  cxLookAndFeelPainters;

type
  TfMedPlotis = class(TGamaForm)
    tsSarasas: TcxTabSheet;
    dbgSarasas: TcxGrid;
    dbgSarasasDBTableView: TcxGridDBTableView;
    dbgSarasasLevel1: TcxGridLevel;
    cxGroupBox1: TcxGroupBox;
    dbnNav: TcxDBNavigator;
    dbgSarasasDBTableViewplotis: TcxGridDBColumn;
    procedure FormShow(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure GmiImportasClick(Sender: TObject);
  private
    { Private declarations }
    m_arImportas: boolean;

    procedure LentelesOn;
    procedure LentelesOff;
    //
    procedure MainBeforeInserOrEdit(DataSet: TDataSet);
    procedure MainBeforePost(DataSet: TDataSet);
    procedure MainAfterPostOrDelete(DataSet: TDataSet);
    procedure MainAfterPostOrDeleteOrCancel(DataSet: TDataSet);
    procedure MainPostError(DataSet: TDataSet;
                E: EDatabaseError; var Action: TDataAction);
    procedure MainNewRecord(DataSet: TDataSet);
  public
    { Public declarations }
    procedure RefreshTables; override;
  end;

var
  fMedPlotis: TfMedPlotis;

implementation

{$R *.dfm}

uses
  bendri, med_dm, Tools;

procedure TfMedPlotis.LentelesOn;
begin
  with dmMed do begin
    tbMedPlotis.BeforeInsert  := self.MainBeforeInserOrEdit;
    tbMedPlotis.BeforeEdit    := self.MainBeforeInserOrEdit;
    tbMedPlotis.BeforePost    := self.MainBeforePost;
    tbMedPlotis.AfterPost     := self.MainAfterPostOrDelete;
    tbMedPlotis.AfterDelete   := self.MainAfterPostOrDelete;
    tbMedPlotis.AfterCancel   := self.MainAfterPostOrDeleteOrCancel;
    //tbMedRastKub.OnPostError   := self.MainPostError;
    tbMedPlotis.OnNewRecord   := self.MainNewRecord;
  end;
end;

procedure TfMedPlotis.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  inherited;
  LentelesOff;
end;

procedure TfMedPlotis.FormShow(Sender: TObject);
begin
  inherited;
  LentelesOn;
end;

procedure TfMedPlotis.GmiImportasClick(Sender: TObject);
begin
  try
    LentelesOff;
    m_arImportas := true;
    fImpExp.DataSet := dmMed.tbMedPlotis;
    dmMed.tbMedPlotis.DisableControls;
    //fImpExp.BeforeStart := ImportBeforeStart;
    //fImpExp.AfterEnd := ImportAfterEnd;
    //dmVagonai.tbVStotys.OnNewRecord := self.StotysNewRecord;
    //fImpExp.BeforeInsert := ImportBeforeInsert;
    fImpExp.ImEx := importas;
    fImpExp.IniFileName := 'ismatavimai.ini';
    if fImpExp.ShowModal(DokTipas) <> mrYes then Exit;
  finally
    m_arImportas := false;
    dmBendras.ApplyUpdatesAfterPostOrDelete( dmMed.tbMedPlotis );
    dmMed.tbMedPlotis.Refresh;
    dmMed.tbMedPlotis.EnableControls;
    bRefreshTables := true;
    //dmVagonai.tbVVagonaiS.Refresh;
    LentelesOn;
  end;
end;

procedure TfMedPlotis.LentelesOff;
begin
  with dmMed do begin
    tbMedPlotis.BeforeInsert  := nil;
    tbMedPlotis.BeforeEdit    := nil;
    tbMedPlotis.BeforePost    := nil;
    tbMedPlotis.AfterPost     := nil;
    tbMedPlotis.AfterDelete   := nil;
    tbMedPlotis.AfterCancel   := nil;
    //tbMedRastKub.OnPostError   := nil;
    tbMedPlotis.OnNewRecord   := nil;
  end;
end;

procedure TfMedPlotis.MainBeforePost(DataSet: TDataSet);
begin
  //MessageText := '';
  //dmBendras.RandomIDBeforePost(DataSet);
end;

procedure TfMedPlotis.MainPostError(DataSet: TDataSet;
                E: EDatabaseError; var Action: TDataAction);
begin
  //dmBendras.RandomIDPostError(DataSet, E, Action);
end;

procedure TfMedPlotis.MainNewRecord(DataSet: TDataSet);
begin
  //
end;

procedure TfMedPlotis.MainAfterPostOrDelete(DataSet: TDataSet);
begin
  dmBendras.ApplyUpdatesAfterPostOrDelete(DataSet);
  MainAfterPostOrDeleteOrCancel(DataSet);
  bRefreshTables := true;
end;

procedure TfMedPlotis.MainAfterPostOrDeleteOrCancel(DataSet: TDataSet);
begin
  SetControlsEditColor( DataSet, GamaPageControl, false );
end;

procedure TfMedPlotis.MainBeforeInserOrEdit(DataSet: TDataSet);
begin
  SetControlsEditColor( DataSet, GamaPageControl, true);
end;

procedure TfMedPlotis.RefreshTables;
begin
  if bRefreshTables then begin
    bRefreshTables := false;
    //dmAlga.tbIssilavLookup.Refresh;
  end
end;

end.
